package com.juc.semaphore.semaphore17;

import java.util.concurrent.Semaphore;

public class Service {
    /**
     * 多进路 ->多处理 -> 多出路实验
     * 允许多个线程同时处理任务，更具体来讲，也就是每个线程都在处理自己的任务
     */
	private Semaphore semaphore = new Semaphore(3);
	
	public void sayHello(){
		try {
			semaphore.acquire();
			System.out.println("threadName = " + Thread.currentThread().getName() + " 准备！ ");
			System.out.println("begin hello " + System.currentTimeMillis());
			for (int i = 0; i < 5; i++) {
				System.out.println(Thread.currentThread().getName() + " 打印 " + (i + 1));
			}
			System.out.println("end hello " + System.currentTimeMillis());
			semaphore.release();
			System.out.println("threadName = " + Thread.currentThread().getName() + " 结束！ ");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
